﻿<%@ Page Language="C#" MasterPageFile="~/Manager.master" AutoEventWireup="true" CodeFile="AddUser.aspx.cs"
    Inherits="Manager_User_AddUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div align="center">
        <table style="width: 100%" border="1" cellpadding="2" cellspacing="2" class="tbl_Comon-Search">
            <tr>
                <td align="left" class="td_Control" colspan="2">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="grpAdd" />
                </td>
            </tr>
           <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label2" runat="server" Text="Tên đăng nhập"></asp:Label></td>
                <td align="left" class="td_Control" nowrap="nowrap">
                    <asp:TextBox ID="txtLogin" Enabled="false" runat="server" Width="70%" ValidationGroup="grpAdd" onblur="fnCheckUser(this.value)"
                        onkeyup="fnHideImg()" CssClass="txt_Product"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLogin"
                        ErrorMessage="Nhập vào tên đăng nhập" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="hidUser"
                        ErrorMessage="Tên truy cập này đã tồn tại" InitialValue="0" ValidationGroup="grpAdd"> &nbsp;</asp:RequiredFieldValidator>&nbsp;
                    <img src="../../Images/Icon/spinner.gif" border="0" id="imgState" style="visibility: hidden" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="hidUser"
                        ErrorMessage="Đang xử lý..." ValidationGroup="grpAdd">Đang xử lý...</asp:RequiredFieldValidator>
                    <asp:TextBox ID="hidUser" runat="server" CssClass="cssHidden" Text="0" Width="5px"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label6" runat="server" Text="Email"></asp:Label></td>
                <td align="left" class="td_Control" nowrap="nowrap">
                    <asp:TextBox ID="txtEmail" Enabled="false" runat="server" ValidationGroup="grpAdd" Width="70%" onblur="fnCheckEmail(this.value)"
                        onkeyup="fnHideImgEmail()" CssClass="txt_Product"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEmail"
                        ErrorMessage="Nhập địa chỉ Email" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail"
                        ErrorMessage="Địa chỉ Email chưa chính xác" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                        ValidationGroup="grpValid">*</asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator51" runat="server" ControlToValidate="hidEmail"
                        ErrorMessage="Địa chỉ Email này đã tồn tại" InitialValue="0" ValidationGroup="grpAdd"> &nbsp;</asp:RequiredFieldValidator>&nbsp;
                    <img src="../../Images/Icon/spinner.gif" border="0" id="imgStateEmail" style="visibility: hidden" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator52" runat="server" ControlToValidate="hidEmail"
                        ErrorMessage="Đang xử lý..." ValidationGroup="grpAdd">Đang xử lý...</asp:RequiredFieldValidator>
                    <asp:TextBox ID="hidEmail" runat="server" CssClass="cssHidden" Text="0" Width="5px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label5" runat="server" Text="Mật khẩu"></asp:Label></td>
                <td align="left" class="td_Control">
                    <asp:TextBox ID="txtPassword" runat="server" Enabled="false" TextMode="Password" ValidationGroup="grpAdd"
                        Width="70%" CssClass="txt_Product"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPassword"
                        ErrorMessage="Nhập vào mật khẩu" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label4" runat="server" Text="Nhập lại mật khẩu"></asp:Label></td>
                <td align="left" class="td_Control">
                    <asp:TextBox ID="txtRePassword" Enabled="false" runat="server" TextMode="Password" ValidationGroup="grpAdd"
                        Width="70%" CssClass="txt_Product"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtPassword"
                        ErrorMessage="Nhập vào mật khẩu" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPassword"
                        ControlToValidate="txtRePassword" ErrorMessage="Mật khẩu chưa khớp nhau" ValidationGroup="grpValid">*</asp:CompareValidator></td>
            </tr>
                        <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label3" runat="server" Text="Quyền hạn"></asp:Label></td>
                <td align="left" class="td_Control">
                    <asp:DropDownList ID="ddlAuthority" Enabled="false" runat="server" ValidationGroup="grpAdd" CssClass="cssDropdownlist">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="ddlAuthority"
                        ErrorMessage="Chọn quyền hạn" InitialValue="0" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator></td>
            </tr>
             <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label1" runat="server" Text="Họ tên"></asp:Label></td>
                <td align="left" class="td_Control">
                    <asp:TextBox ID="txtMenu" runat="server" Width="70%" ValidationGroup="grpAdd" CssClass="txt_Product"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtMenu"
                        ErrorMessage="Nhập họ tên" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator></td>
            </tr>
            
            <tr>
                <td class="td_Title" style="width: 123px">
                    <asp:Label ID="Label7" runat="server" Text="Giới tính"></asp:Label></td>
                <td align="left" class="td_Control">
                    <asp:DropDownList ID="ddlSex" runat="server" CssClass="cssDropdownlist">
                        <asp:ListItem Value="0">Nam</asp:ListItem>
                        <asp:ListItem Value="1">Nữ</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>            

            <tr>
                <td colspan="2" style="padding-left: 125px" align="left">
                    &nbsp;</td>
            </tr>
            <tr>
                <td style="width: 123px">
                </td>
                <td style="height: 24px" align="left">
                    <!--<asp:Button ID="btnAdd_ChuDe" runat="server" Text="Thêm mới" CssClass="cssButton" />-->
                    <asp:Button ID="btnAdd" runat="server" CssClass="cssButton" Text="Bảo lưu" Width="80px"
                        OnClick="btnAdd_Click" ValidationGroup="grpAdd" />
                    <asp:Button ID="btnCancel" runat="server" CssClass="cssButton" Text="Trở về" OnClick="btnCancel_Click"
                        Width="80px" /></td>
            </tr>
        </table>
    </div>

    <script language="javascript" type="text/javascript">
    String.prototype.trim = function () {
		return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}

    /*=================User================*/
    function fnHideImg()
    {
        var imgState=document.getElementById("imgState");
        imgState.style.visibility="hidden"; 
    }
    function fnCheckUser(sValue)
    {     
    
        if(sValue.trim()=="" || sValue.trim().toLowerCase()=="administrator" )
        {   
            var hidUser=document.getElementById("<%= hidUser.ClientID%>");
            hidUser.value="0";
            return;
        }
        var UserID="0";
        if('<%=Request.QueryString["UserID"] %>'!="" && '<%= Request.QueryString["UserID"]%>'!=null)
            UserID='<%=Request.QueryString["UserID"] %>';
    
        Manager_User_AddUser.AjaxCheckUser(sValue,UserID,CallBackUser);  
        var imgState=document.getElementById("imgState");
        imgState.style.visibility="visible";
        imgState.src="../../Images/Icon/spinner.gif";     
    }
    function CallBackUser(res)
    {
        if(res!=null)
        {
            var flag=res.value;
            if(flag!=null && flag!="")
			{	
			    var imgState=document.getElementById("imgState");
			    //var hidUser=document.getElementById("ctl00_ContentPlaceHolder1_hidUser");
			    var hidUser=document.getElementById("<%= hidUser.ClientID%>");
			    hidUser.value="aaa";
			    imgState.style.visibility="visible";
			    if(flag=="yes")
			    {
			        imgState.src="../../Images/Icon/cmdDelete.gif";
			        imgState.alt="Tên này đã tồn tại";
			        hidUser.value="0";
			    }
			    else
			    {
			        imgState.src="../../Images/Icon/check.gif";
			        imgState.alt="Bạn được sử dụng tên này";
			    }
			}	
        }
    }
    
/*=================Email================*/
    function fnHideImgEmail()
    {
        var imgStateEmail=document.getElementById("imgStateEmail");
        imgStateEmail.style.visibility="hidden"; 
    }
    function fnCheckEmail(sValue)
    {      
         if(sValue.trim()=="" )
        {   
            var hidUser=document.getElementById("<%= hidUser.ClientID%>");
            hidUser.value="0";
            return;
        }
        
        var UserID="0";
        if('<%=Request.QueryString["UserID"] %>'!="" && '<%= Request.QueryString["UserID"]%>'!=null)
            UserID='<%=Request.QueryString["UserID"] %>';
        Manager_User_AddUser.AjaxCheckEmail(sValue,UserID,CallBackEmail);  

     
    }
    function CallBackEmail(res)
    {
        if(res!=null)
        {
            var flag=res.value;
            if(flag!=null && flag!="")
			{	
			    var imgStateEmail=document.getElementById("imgStateEmail");

			    var hidEmail=document.getElementById("<%= hidEmail.ClientID%>");
			    hidEmail.value="aaa"; //Tranh su kien dang su ly
		
			    if(flag=="yes")
			    {   imgStateEmail.style.visibility="visible";
			        imgStateEmail.src="../../Images/Icon/cmdDelete.gif";
			        imgStateEmail.alt="Email này đã tồn tại";			        
			        hidEmail.value="0";
			       
			    }		
			    else
			    {
			           imgStateEmail.style.visibility="hidden";
			    }	    
			}	
        }
    }

 
    </script>

</asp:Content>
